package Arrays;

import java.util.Stack;

/**
 * 作者:hfj
 * 功能:232.用栈实现队列
 * 日期: 2025/10/28 20:07
 */
public class MyQueue {
    private Stack<Integer> in = new Stack<>();
    private Stack<Integer> out = new Stack<>();
    public void push(int x) {
        in.push(x);
    }
    public int pop() {
        peek();
        return out.pop();
    }

    public int peek() {
        if (out.isEmpty())
            while (!in.isEmpty())
                out.push(in.pop());
        return out.peek();
    }

    public boolean empty() {
        return in.isEmpty() && out.isEmpty();
    }
}
